.global _memputb
.global _memputw
.global _memgetb
.global _memgetw
.global _memsetw

;------------------------------------------------------------------------------
; Write a byte at the specified segment:offset address.
; memputb(uint segment, uint offset, uchar byte)

_memputb:
	push bp
	mov bp,sp

	push es
	push di
	mov ax,[bp+4]
	mov es,ax
	mov di,[bp+6]
	mov ax,[bp+8]
	seg es
	mov byte [di],al
	pop di
	pop es

	pop bp
	ret

;------------------------------------------------------------------------------
; Write a word (16-bit) at the specified segment:offset address.
; memputw(uint segment, uint offset, uint word)

_memputw:
	push bp
	mov bp,sp

	push es
	push di
	mov ax,[bp+4]
	mov es,ax
	mov di,[bp+6]
	mov ax,[bp+8]
	seg es
	mov word [di],ax
	pop di
	pop es

	pop bp
	ret

;------------------------------------------------------------------------------
; Read a byte from the specified segment:offset address.
; memgetb(uint segment, uint offset)

_memgetb:
	push bp
	mov bp,sp

	push es
	push di
	mov ax,[bp+4]
	mov es,ax
	mov di,[bp+6]
	seg es
	mov al,byte [di]
	xor ah,ah
	pop di
	pop es

	pop bp
	ret

;------------------------------------------------------------------------------
; Read a word (16-bit) from the specified segment:offset address.
; memgetw(uint segment, uint offset)

_memgetw:
	push bp
	mov bp,sp

	push es
	push di
	mov ax,[bp+4]
	mov es,ax
	mov di,[bp+6]
	seg es
	mov ax,word [di]
	pop di
	pop es

	pop bp
	ret



;------------------------------------------------------------------------------
; Write the specified count of words (16-bit) at segment:offset.
; void memsetw(uint seg, uint offset, uint value, uint count)

_memsetw:
        push bp
        mov bp,sp
        push es

        mov ax,[bp+4]   ; segment
        mov es,ax
        mov di,[bp+6]   ; offset
        mov ax,[bp+8]   ; value
        cld
        mov cx,[bp+10]  ; count
fillw:  stosw
        loop fillw

        pop es
        pop bp
	ret
